package com.aletto.general_store.presenters;


import androidx.recyclerview.widget.RecyclerView;


import com.aletto.general_store.data.DataRepository;
import com.aletto.general_store.data.model.ConsumerOrder;

import com.aletto.general_store.data.model.PageResponse;
import com.aletto.general_store.presenters.core.SimplePageTemplate;
import com.aletto.general_store.ui.adapters.ConsumerOrderAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.sisyphus.spinach.core.INetPageTask;

import com.sisyphus.spinach.core.model.IPageResponse;
import com.sisyphus.spinach.core.model.IResponse;
import com.sisyphus.spinach.network.presenters.NetPageTask;


import io.reactivex.rxjava3.core.Observable;

public class ConsumerOrderPageTemplate extends SimplePageTemplate<ConsumerOrder> {

    private int type;
    private String keyword;

    public ConsumerOrderPageTemplate(RecyclerView recyclerView, SmartRefreshLayout refreshLayout) {
        super(recyclerView, refreshLayout);
    }

    public void setParams(int type, String keyword) {
        this.type = type;
        this.keyword = keyword;
    }

    @Override
    public BaseQuickAdapter<ConsumerOrder, BaseViewHolder> adapter(RecyclerView recyclerView) {
        return new ConsumerOrderAdapter();
    }

    @Override
    public INetPageTask.Presenter<ConsumerOrder, INetPageTask.View<ConsumerOrder>> presenter() {
        return new NetPageTask<>() {
            @Override
            public Observable<? extends IResponse<? extends IPageResponse<ConsumerOrder>>> execute(int page) {
                return DataRepository.getInstance().myOrderList(page, PageResponse.SIZE, type, keyword);
            }
        };
    }
}
